/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ihmprojet.view.renderer;

import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.visualization.RenderContext;
import edu.uci.ics.jung.visualization.renderers.BasicRenderer;
import ihmprojet.core.model.DelegateTreeOperators;
import ihmprojet.core.model.GraphOperator;
import ihmprojet.core.model.Sommet;
import java.util.ConcurrentModificationException;
import java.util.Map;

/**
 *
 * @author Rémi PIOTAIX <remi.piotaix@gmail.com>
 */
public class TreeOperatorRenderer<V extends Sommet, E> extends BasicRenderer<V, E> {

    @Override
    public void render(RenderContext<V, E> renderContext, Layout<V, E> layout) {
        try {
            if (!(layout.getGraph() instanceof DelegateTreeOperators)) {
                return;
            }
            DelegateTreeOperators tree = (DelegateTreeOperators) layout.getGraph();
            Map<V, GraphOperator<V, E>> operateurs = tree.getOperateurs();
            for (V vertex : operateurs.keySet()) {
                GraphOperator<V, E> operator = operateurs.get(vertex);
                renderEdge(renderContext, layout, operator.getEdge());
                renderEdgeLabel(renderContext, layout, operator.getEdge());
            }
        } catch (ConcurrentModificationException cme) {
            renderContext.getScreenDevice().repaint();
        }
        super.render(renderContext, layout);
    }
}
